//
//  QJMineSKJLVC.m
//  QuanJieShopProject
//
//  Created by 刘中义 on 2018/2/28.
//  Copyright © 2018年 apple. All rights reserved.
//

#import "QJMineSKJLVC.h"
#import "UIScrollView+EmptyDataSet.h"
#import "QJMineSKJLCell.h"
@interface QJMineSKJLVC () <UITableViewDelegate,UITableViewDataSource,DZNEmptyDataSetDelegate,DZNEmptyDataSetSource>
@property (nonatomic, strong) UITableView *jlTableView;
@property (nonatomic, strong) NSMutableArray *dataSourceArray;
@end

@implementation QJMineSKJLVC

- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view.
    self.title = @"收款记录";
    [self setupJLUIAction];
    [self dataMyshopRecordRequestAction];
//    [self dataUserRecordDataRequestAction];
}

#pragma mark -- 界面布局
- (void)setupJLUIAction{
    self.dataSourceArray = [NSMutableArray array];
    self.jlTableView = [[UITableView alloc]initWithFrame:CGRectMake(0, 0, UISCREEN_WIDTH, UISCREEN_HEIGHT) style:UITableViewStylePlain];
    [self.view addSubview:self.jlTableView];
    self.jlTableView.delegate = self;
    self.jlTableView.dataSource = self;
    self.jlTableView.emptyDataSetDelegate = self;
    self.jlTableView.emptyDataSetSource = self;
    self.jlTableView.separatorStyle = UITableViewCellSeparatorStyleNone;
}
#pragma mark -- 数据请求方法
- (void)dataMyshopRecordRequestAction{
    [WWNetRequest fetchMyshopRecordWithParameters:nil success:^(id response) {
        
        NSLog(@"收款记录 response = %@", response);
        NSArray *dataArr = response[@"data"][@"order_list"];
        NSLog(@"dataArr = %@", dataArr);
        NSMutableArray *array = [NSMutableArray array];
        if (dataArr.count) {
            for (NSDictionary *dict in dataArr) {
                MineSKJLModel *model = [[MineSKJLModel alloc]initWithDictionary:dict error:nil];
                model.mobile =  [model.user objectForKey:@"mobile"];
                [array addObject:model];
            }
        }
        self.dataSourceArray = array;
        [self.jlTableView reloadData];
    } failure:^(NSDictionary *error) {
        NSLog(@"收款记录 error = %@", error);

    }];
}
#pragma mark -- 数据请求方法
- (void)dataUserRecordDataRequestAction{
    
    [WWNetRequest fetchUserRecordWithParameters:nil success:^(id response) {
        
        NSLog(@"收款记录 response = %@", response);
        NSArray *dataArr = response[@"data"][@"order_list"];
        NSLog(@"dataArr = %@", dataArr);
        NSMutableArray *array = [NSMutableArray array];
        if (dataArr.count) {
            for (NSDictionary *dict in dataArr) {
                MineSKJLModel *model = [[MineSKJLModel alloc]initWithDictionary:dict error:nil];
                model.mobile =  [model.user objectForKey:@"mobile"];
                [array addObject:model];
            }
        }
        self.dataSourceArray = array;
        [self.jlTableView reloadData];
    } failure:^(NSDictionary *error) {
        NSLog(@"收款记录 error = %@", error);
        
    }];
}
#pragma mark -- UITableViewDataSource
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{
    return self.dataSourceArray.count;
}
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{
    static NSString *cellID = @"cellID";
    QJMineSKJLCell *cell = [tableView dequeueReusableCellWithIdentifier:cellID];
    if (cell == nil) {
        cell = [[[NSBundle mainBundle]loadNibNamed:@"QJMineSKJLCell" owner:self options:nil]lastObject];
    }
    cell.selectionStyle = UITableViewCellSelectionStyleNone;
    MineSKJLModel *model = self.dataSourceArray[indexPath.row];
    [cell cellUpdateWithModel:model];
    return cell;
}
#pragma mark -- UITableViewDelegate
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath{
}
- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath{
    
    return 129;
}
#pragma mark -- DZNEmptyDataSetSource
- (UIImage *)imageForEmptyDataSet:(UIScrollView *)scrollView
{
    return [UIImage imageNamed:@"noDataImage"];
}
#pragma mark -- DZNEmptyDataSetDelegate
- (BOOL)emptyDataSetShouldAllowScroll:(UIScrollView *)scrollView{
    return YES;
}
- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}



@end
